<template>
  <u-form labelWidth="auto" disabled :labelStyle="labelStyle">
    <view>
			<view style="display: flex;">
				<view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">物料大类</view>
						<view class="rl">{{ item.provisionBroad_dictText }}</view>
					</view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">物料小类</view>
						<view class="rl">{{ item.provisionSmall_dictText }}</view>
					</view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">物料编码</view>
						<view class="rl">{{ item.materialBill }}</view>
					</view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">物料名称</view>
						<view class="rl">{{ item.materialName_dictText }}</view>
					</view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">规格型号</view>
						<view class="rl">{{ item.specification }}</view>
					</view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">单位</view>
						<view class="rl">{{ item.unit_dictText }}</view>
					</view>
					<view class="option" style="width: 520rpx;">
						<view class="lf">品牌</view>
						<view class="rl">{{ item.brand }}</view>
					</view>
					<u-form-item label="供应商" prop="companName">
						<h-select-customer-input-popup style="width: 100%" ref="projectSelect" v-model="item.companName" commercialType="2"
							auditStatus="2" suffixIcon="edit-pen-fill" placeholder="请选择供应商" border="none"  :proDisabled="true">
						</h-select-customer-input-popup>
					</u-form-item>
					<u-form-item label="领用数量" prop="recipientsNum" required>
						<h-number-input
							placeholder="请输入领用数量"
							v-model="item.recipientsNum"
							border="none"
							:digit="0"
							:max="99999999"
							:min="1"
							suffixIcon="edit-pen-fill"
						></h-number-input>
					</u-form-item>
					<u-form-item label="物料用途" prop="remark">
						<u--textarea v-model="item.remark" autoHeight confirmType="done" placeholder="请输入物料用途"
							:maxlength="500" border="none"></u--textarea>
					</u-form-item>
				</view>
				
				<view  style="flex: 1; display: flex; align-items: center; justify-content: flex-end;">
					<u-icon name="trash-fill" color="red" size="20"  @click="handleRemoveForm(item)"></u-icon>
				</view>
			</view>
    </view>
  </u-form>
</template>

<script>
import { queryByDepartment, queryProvisionBroadList, queryProvisionSmallList } from '@/api/purchase/ErpPurchaseCannibalizeForm'
import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
export default {
  name: 'ErpPurchaseApplyMaterialFormInfo',
  props: {
    index: {
      type: Number,
      default: null,
    },
    item: {
      type: Object,
      default: () => ({}),
    },
    provisionBroad: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
			labelStyle: {
				color: '#b2b2b2'
			},
      filterMultiDictText,
      initDictOptions,
      dictOptions: {},
      smallList: [],
      api: {
        queryByDepartment,
        queryProvisionBroadList,
      },
    }
  },
  watch: {
    item: {
      handler(val) {
        if (val && val.provisionBroad) {
          this.initSmallType()
        }
      },
      immediate: true,
      deep: true,
    },
    provisionBroad: {
      handler(val) {
        if (val) {
          this.findProvisionSmallList(val)
        }
      },
      deep: true,
    },
  },
  created() {
    this.provisionBroad && this.findProvisionSmallList(this.provisionBroad)
  },
  methods: {
    initSmallType() {
      this.exportWarehouseChange(this.item.provisionBroad)
    },
    exportWarehouseChange(id) {
      // this.provisionSmallChange()
      this.smallList = []
      if (id) {
        this.findProvisionSmallList(id)
      }
    },
    findProvisionSmallList(value) {
      const parentId = value
      queryProvisionSmallList({ parentId }).then((res) => {
        if (res.success) {
          const data = res.result.map((item) => {
            return { id: item.id, categoryName: item.categoryName }
          })
          this.smallList = [data]
        } else {
          this.$u.toast(res.message)
        }
      })
    },
    handleCopyForm(item) {
      this.$emit('copy', [item, this.index])
    },
    handleEidtForm(item) {
      this.$emit('edit', [item, this.index])
    },
    handleRemoveForm(item) {
			uni.showModal({
				content: '确定删除吗？',
				success: res => {
					if (res.confirm) {
						this.$emit('remove', item)
					}
				}
			});
    },
  }
}
</script>

<style scoped lang="scss">
.inforamtion {
  margin-top: 10rpx;
  padding: 10rpx;
  border-radius: 15rpx;
  box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.1);
}
/deep/ .u-form-item__body{
	padding: 0px !important;
}
</style>
